import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NzModalService } from 'ng-zorro-antd';
import { CustomService } from 'src/app/service/custom.service';

@Component({
  selector: 'app-refuse-words',
  templateUrl: './refuse-words.component.html',
  styleUrls: ['./refuse-words.component.less']
})
export class RefuseWordsComponent implements OnInit {

  validateForm!: FormGroup;
  data: any = {};

  submitForm() {
    var data = this.validateForm.value;
    data.refuseWords = data.refuseWords.replace(/(^\s*)|(\s*$)/g, "");
    this.customService.modify(data).subscribe(result => {
      this.modalService.success({
        nzTitle: '信息提示',
        nzContent: '拒绝词汇修改成功!'
      });
    });
  }

  constructor(
    private fb: FormBuilder,
    private modalService: NzModalService,
    private customService: CustomService
  ) { }

  ngOnInit(): void {
    this.customService.profile().subscribe(result => {
      let data = result['data'];
      this.data = data;
      this.validateForm.setValue({
        refuseWords: data['refuseWords']
      });
    });
    this.validateForm = this.fb.group({
      refuseWords: [null]
    });
  }

}
